#include "mysqllink.h"

MysqlLink::MysqlLink(QObject *parent) :
    QThread(parent)
{
       //read_ini();
      /*if(sysInfo->serverIp.indexOf(":")>0)
       {
           =sysInfo->serverIp.section(":",0,0);
       }else{
        ip=sysInfo->serverIp;
       }*/
       user=sysInfo->userName;
       password=sysInfo->passWord;
       dateBaseName=sysInfo->datebaseName;
       mySql_db =QSqlDatabase::addDatabase("QMYSQL","ment");
       mySql_db.setHostName(sysInfo->mysqlServerIp);
       mySql_db.setDatabaseName(dateBaseName);
       mySql_db.setUserName(user);
       mySql_db.setPassword(password);
       mySql_db.setPort(3306);
       qDebug()<<"mysqlconnect"<<ip<<dateBaseName<<user<<password;
}

void MysqlLink::run()
{
    mySql_db.open();
}

void MysqlLink::read_ini()
{
    QFile file("camera.ini");
    if(file.open(QFile::ReadOnly))
    {
        file.readLine();
        file.readLine();
        ip=file.readLine().trimmed();
        file.close();
    }else{
        QFile file1("camera.ini");
        if(file1.open(QFile::WriteOnly))
        {
            QTextStream out1(&file1);
            out1<<"127.0.0.1"<<"\r\n"<<"127.0.0.1"<<"\r\n"<<"127.0.0.1"<<"\r\n"<<"127.0.0.1"<<"\r\n";
            out1.seek(out1.pos());//定位文件当前
            //file.write("\r\n");//换行符
            ip="127.0.0.1";
            file1.close();
        }
    }
}
